package com.suntront.module_metertask.sort

import android.view.Menu
import android.view.MenuItem
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mtjsoft.www.kotlinmvputils.base.BaseRecycleViewModel
import com.mtjsoft.www.kotlinmvputils.base.BaseRecycleviewActivity
import com.mtjsoft.www.kotlinmvputils.constants.RouterConstants
import com.suntront.lib_db.table.UserT
import com.suntront.module_metertask.R
import com.suntront.module_metertask.adapter.UserTSortAdapter

/**
 * 抄表排序
 * @author mtj
 * @Package com.suntront.module_metertask.sort
 * @date 2020-05-27 16:24:47
 */
@Route(path = RouterConstants.MeterTask_UserTSort)
class UserTSortRecycleViewActivity : BaseRecycleviewActivity<UserT, UserTSortViewModel>() {

    /**
     * 注入路由传递的参数
     * rosterId  表册id
     */
    @JvmField
    @Autowired
    var rosterId = 0

    override fun providerVMClass(): Class<UserTSortViewModel>? {
        return UserTSortViewModel::class.java
    }

    override fun loadActivityInfo() {
        setPageTitle("抄表排序")
        viewModel.refresh.value = false
        viewModel.load_more.value = false
        viewModel.rosterId = rosterId
        viewModel.isDrag.value = true
    }

    override fun setItemDecoration(): Int {
        return 10
    }

    override fun setPageSize(): Int {
        return Int.MAX_VALUE
    }

    override fun setLayoutManagerType(): BaseRecycleViewModel.LayoutManager {
        return BaseRecycleViewModel.LayoutManager.GridLayoutManager
    }

    override fun setCount(): Int {
        return 3
    }

    override fun instanceAdapter(list: MutableList<UserT>): BaseQuickAdapter<UserT, BaseViewHolder> {
        return UserTSortAdapter(getContext(), list)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.save_text, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        when(item?.itemId) {
            R.id.save -> {
                viewModel.save()
            }
        }
        return super.onOptionsItemSelected(item)
    }
}